The present invention relates generally to a class of semiconductor microprocessors utilized as microcontrollers to perform selective control functions on an external controlled system.
Microcontrollers having all peripherals embedded on the same single microcontroller chip have become increasingly popular in a large number of diverse control applications. These include, for example, pocket pagers, meters and testers, keyboard controllers capable of offloading many tasks which would otherwise require handling by the processor in personal computers, modems for command interpretation and data transmission, printer buffers for high speed data dumping, color plotters, color copiers, electronic typewriters, cable TV terminal equipment, lawn sprinkling controllers, credit card phone equipment, automotive applications including engine control modules, antilock braking systems, user-adjustable suspension control, and various other applications in industrial controls, telecommunications, automotive, appliance, computer and consumer markets.
Real time microcontrollers provide rapid solutions to signal processing algorithms and other numerically intensive computations, control events such as opening and closing of relays, position and speed of a motor, and other control functions. The central processing unit (CPU) of the microcontroller operates in conjunction with certain peripherals to perform the control function, including timers, signal ports, baud rate generators, and others.
Generally, one or more timers (typically registers which are, say, 8 or 16 bit wide) are fabricated on board the microcontroller chip (i.e., integrated within the circuitry of the single chip itself). The timers are utilized to implement various timing functions of the device. One may be a capture function, which enables recording a time stamp of the occurrence of an event of interest. For example, the event of interest may be a change in the logic state at an external pin, from "0" to "1", or "1" to "0". To capture the precise moment at which the pin change occurs, a 16 bit wide timer might be used together with a 16 bit wide shadow register that acts as a capture register. When the pin bit value changes, the timer value (count) is captured on the shadow register. Upon completion of the transfer, an interrupt is generated to the CPU of the microcontroller. Then, after the CPU has completed the task it was performing when the change took place, it can check on the timing of the event of interest at its leisure.
Another timing function--a compare function--is often used in microcontrollers to generate an event of some type, such as a pulse, or a change in logic state of a pin. A time base is provided by the timer (e.g., 16 bit wide), but in this case the associated shadow register (compare register) writes the value or time stamp for the desired time of occurrence of the event. Thus, the compare function of a microcontroller device allows the user to set an event to occur at a precise specified time or times.
The present invention is directed to yet another timing function commonly employed in microcontrollers, namely, pulse width modulation (PWM). PWM involves repetitive events, in contrast to the single occurrence event `capture` and `compare` functions. With PWM, a repetitive waveform may be generated at a pin, with a period in which the pin is at one logic state (e.g., high) for a specified time interval, and at another logic state (e.g., low) for another specified time interval. The timing of the high and low states is selected to modulate the width of the pulse. The period of the PWM is the sum of the high and low intervals, and is determined by the timer.
PWM is especially useful to generate analog signals. For an 8 bit entity, for example, the pulse width may be set at any value between 0 and 255. A large number is thereby encoded into a digital signal, which is then used to generate an analog signal for performing the desired function, such as to drive a motor. The motor can be run at a slow rate by making the pulse width commensurately small, and at a faster rate by concomitantly increasing the pulse width.
The period of the repetitive waveform of the PWM function may be selected by the user, as a fixed number written into a register at the outset. Or it may be desired to change the waveform period or duty cycle at various times, such as to ramp up the speed of a motor. The user may want to eliminate noise encountered in the operation of a personal computer which is attributable to moving pans, such as a fan driven by PWM from the microcontroller. To that end, since noise or whine occurs from vibrations at frequencies in the audible range up to about 20 kilohertz (KHz), it would be desirable to run the mechanical parts in question at a frequency that exceeds 20 KHz. A contrasting example of the use of PWM is in an industrial control requiring a large motor to be driven. There, it is necessary to select a much lower frequency PWM waveform, e.g., on the order of 1 KHz, because of the inability of a large motor to respond to higher frequencies with any significant power efficiency.
It would be desirable to provide flexibility in specifying the duty cycle of the PWM timing function, to accommodate different applications of the microcontroller in which operating frequencies may range from the low to the high extremes.
The time base of the PWM module of the microcontroller is provided by a timer incremented from zero to a count that matches the value written by the user to a register. When the match occurs, the timer is automatically reset and the count restarted at zero. By writing an appropriate value to the register, the timer controls the period of the repetitive waveform. An interrupt is generated is also generated periodically in synchronism with each period of the PWM waveform. This imposes greater overhead on the CPU and adversely affects the overall operation of the microcontroller by slowing the performance of the CPU.
Therefore, it is a principal important object of the present invention to avoid the necessity for constant interrupts of the CPU of the microcontroller, while still maintaining considerable latitude to alter the period and the duty cycle of the PWM waveform.